package com.coffee.mycoffee.config.exception;


import com.coffee.mycoffee.config.utils.Resp;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理类(让异常结果也显示为统一的结果对象)
 */
@RestControllerAdvice
public class ExceptionController {

    /**
     * 统一异常处理类
     *
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public Resp exceptionHandler(RuntimeException e) {
        return Resp.error().msg(e.getMessage());
    }

    /**
     * 自定义异常处理类
     *
     * @param e
     * @return
     */
    @ExceptionHandler(CoffeeException.class)
    public Resp exceptionHandler(CoffeeException e) {
        return Resp.error().msg(e.getMsg());
    }

}
